
package com.j2eefast.produce.pms.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.UserUtils;
import com.j2eefast.produce.pms.entity.PmsReviewEntity;
import com.j2eefast.produce.pms.entity.PmsReviewReportEntity;
import com.j2eefast.produce.pms.mapper.PmsReviewMapper;
import com.j2eefast.produce.pms.mapper.PmsReviewReportMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>评审报备</p>
 *
 * @author: summer
 * @date: 2021-05-28 16:47
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */
@Service
@Transactional(readOnly = true)
public class PmsReviewReportService extends ServiceImpl<PmsReviewReportMapper, PmsReviewReportEntity> {

	@Resource
	protected PmsReviewReportMapper pmsReviewReportMapper;
	@Resource
	protected PmsReviewMapper pmsReviewMapper;

	/**
	 * 页面展示查询翻页
	 */
	public PageUtil findPage(Map<String, Object> params) {
		String name = (String) params.get("name");
//		String sampleType = (String) params.get("sampleType");
//		String name="";
//		if(id!=""){
//			PmsReviewEntity pmsReviewEntity= pmsReviewMapper.selectById(id);
//			name=pmsReviewEntity.getProjectName();
//		}
		Page<PmsReviewReportEntity> page = pmsReviewReportMapper.findPage(
				new Query<PmsReviewReportEntity>(params).getPage(),
				StrUtil.nullToDefault(name,""),
//				StrUtil.nullToDefault(sampleType,""),
				(String) params.get(Constant.SQL_FILTER));
//		Page<PmsReviewEntity> page1=new Page<PmsReviewEntity>();
//		for(int i=0;i<page.getRecords().size()-1;i++){
//			System.out.println("22222222");
//			System.out.println(page.getRecords().get(i).getProjectName().contains(page.getRecords().get(i+1).getProjectName()));
//			System.out.println("111111111111111");
//			if(page.getRecords().get(i).getProjectName().contains(page.getRecords().get(i+1).getProjectName())){
//				page1.getRecords().add(page.getRecords().get(i));
//			}
//		}
		return new PageUtil(page);
	}
	@Transactional(rollbackFor = Exception.class)
	public boolean deleteByIds(Long[] ids) {

		return pmsReviewReportMapper.deleteByIds(ids);

	}
	@Transactional(rollbackFor = Exception.class)
	public boolean updateCheck(Long id) {
		Long userId= UserUtils.getUserInfo().getId();

		return pmsReviewReportMapper.updateCheck(id ,userId);

	}


	public List<PmsReviewReportEntity> reportList(String name){
		return pmsReviewReportMapper.reportList(name);
	}



}
